#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP

#include <QMainWindow>
#include <QGridLayout>
#include <QHash>

#include "connection.hpp"
#include "player.hpp"
#include "client.hpp"
#include "lobby.hpp"
#include "game.hpp"
#include "gamewindow.hpp"

class Client;
class Lobby;
class Game;
class GameWindow;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);

    Lobby * lobby() const;

private:
    QGridLayout *_layout;

    Connection * _connection;
    Client * _client;
    Player * _player;
    Lobby * _lobby;
    QHash<quint8, Game *> _gameHash;
    QHash<quint8, GameWindow *> _gameWindowHash;

protected:
    void closeEvent(QCloseEvent * event);

public slots:
    void reactConnectionSuccess();
    void reactInscription();
    void reactMotd(const QString & message);
    void reactDisconnection();
    void reactConnected();

    void reactGameCreated(quint8 idPartie, quint8 gobanSize, qreal komi, const QString & black);
    void reactGameDestroyed(quint8 idPartie);
    void reactGameList(const QList<Game *> & list);

    void reactGameWindowClosed(quint8 id);
    void reactWantToOpenAGameWindow(quint8 id);

    void reactHeSees(quint8 idPartie, const QString & name);
    void reactHeDoesntSeeAnymore(quint8 idPartie, const QString & name);
    void reactGameStarts(quint8 idPartie, const QString & name);

    void reactGameLeft(quint8 idPartie, quint8 playerID);

    void reactGameSaid(quint8 idPartie, const QString & message);

    void reactGameState(quint8 idPartie, const QStringList & observerList, const QVector < QVector<quint8> > & map);
    void reactObserverList(quint8 idPartie, const QStringList & observerList);

    void reactMovePlayed(quint8 idPartie, quint8 playerID, quint8 x, quint8 y);
    void reactBadMove(quint8 idPartie);
    void reactNewScore(quint8 idPartie, quint8 playerID, qreal newScore);
    void reactTurnSkipped(quint8 idPartie, quint8 playerID);
    void reactMovesFinished(quint8 idPartie);
    void reactGroupKilled(quint8 idPartie, quint8 x, quint8 y);
    void reactGroupSaved(quint8 idPartie, quint8 x, quint8 y);

    void reactToPlayAgain(quint8 idPartie);
    void reactGroupsValidated(quint8 idPartie, quint8 playerID);
    void reactGameover(quint8 idPartie, qreal blackScore, qreal whiteScore);

private slots:
    void displayLobby(QString pseudo);
};

#endif // MAINWINDOW_HPP
